package com.huawei.appgallery.festivalanimation.particle.modifiers;

import android.util.Log;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.huawei.appgallery.festivalanimation.particle.Particle;

public class SizeModifier implements IParticleModifier {
    public static final float STABLE_STATE_SCALE = -1.0f;
    private long mDuration;
    private long mEndTime;
    private float mFinalValue;
    private float mInitialValue;
    private Interpolator mInterpolator;
    private long mStartTime;

    public SizeModifier(float f, float f2, long j, long j2, Interpolator interpolator) {
        this.mInitialValue = f;
        this.mFinalValue = f2;
        this.mStartTime = j;
        this.mEndTime = j2;
        this.mDuration = this.mEndTime - this.mStartTime;
        this.mInterpolator = interpolator;
    }

    public SizeModifier(float f, float f2, long j, long j2) {
        this(f, f2, j, j2, new LinearInterpolator());
    }

    private float getInitialScale(Particle particle) {
        return this.mInitialValue == STABLE_STATE_SCALE ? particle.mScale : this.mInitialValue;
    }

    private float getFinalScale(Particle particle) {
        return this.mFinalValue == STABLE_STATE_SCALE ? particle.mInitialScale : this.mFinalValue;
    }

    private float getValueIncrement(Particle particle) {
        return getFinalScale(particle) - getInitialScale(particle);
    }

    public void modify(Particle particle, long j) {
        if (j >= this.mStartTime && j <= this.mEndTime) {
            float interpolation = this.mInterpolator.getInterpolation((((float) (j - this.mStartTime)) * 1.0f) / ((float) this.mDuration));
            interpolation = (interpolation * getValueIncrement(particle)) + getInitialScale(particle);
            Log.d("DEBUG_SYS", "newScale: " + interpolation);
            particle.mScale = interpolation;
        }
    }
}
